home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Periodicals / develop / develop 5 code / Scanning from ProDOS / Dev.Sample.aii next >
Encoding:
Text File  |  1990-11-06  |  24.3 KB  |  1,028 lines  |  [TEXT/MPS ]

  1.  
  2. ;*******************************************************
  3. ;
  4. ;    Develop Code Samples.
  5. ;
  6. ;    Written by Matt Gulick.        Started October 16,1990
  7. ;
  8. ;*******************************************************
  9.  
  10. ;*******************************************************
  11. ;
  12. ;    This file contains the code samples that are used in
  13. ;    the Scanning From ProDOS article in DEVELOP.  These
  14. ;    code segments may be used freely by anyone.  All
  15. ;    code in this file assumes that we are running in an
  16. ;    8 bit Apple IIe.
  17. ;
  18. ;*******************************************************
  19.  
  20. ;*******************************************************
  21. ;
  22. ;    Revision History:
  23. ;
  24. ;*******************************************************
  25.  
  26. ;    Oct  16, 1990    File started.
  27. ;
  28.  
  29.             STRING        PASCAL
  30.             BLANKS        OFF
  31.             PAGESIZE    70
  32.             PRINT        NOGEN
  33.             PRINT        NOMDIR
  34.             MACHINE        M65C02
  35.  
  36.             EJECT
  37.             
  38. ;*******************************************************
  39. ;
  40. ;    CODE SAMPLE #1
  41. ;
  42. ;    This first code segment walks the slots starting at
  43. ;    slot 7, looking first for a card of any kind.  Once
  44. ;    found, we check the ID bytes for a Smartport card.
  45. ;    Once found we check the ID Type byte to see if it is
  46. ;    a SCSI Card.  If it passes all these tests, we then
  47. ;    issue a Device $00 Status $00 call to further ensure
  48. ;    that this is the Apple High-Speed SCSI Card.
  49. ;
  50. ;*******************************************************
  51.  
  52.                                 ;
  53.                                 ; The following are Equates
  54.                                 ; that will bee used in all
  55.                                 ; the Sample Code Segments
  56.                                 ; that follow.
  57.                                 ;
  58. slot_7        equ        $C7
  59. slot_1        equ        $C1
  60.  
  61. My_ZPage    equ        $42
  62.  
  63. KBD            equ        $C000        ;Keyboard
  64. CLR80VID    equ        $C00C        ;Disable 80-column hardware
  65. SET80VID    equ        $C00D        ;Enable 80-column hardware
  66. KBD_STRB    equ        $C010        ;Keyboard Strobe
  67. RD80COL        equ        $C018        ;Read 80 Col. Mode
  68. RDTEXT        equ        $C01A        ;Read Text Mode
  69. RDMIX        equ        $C01B        ;Read Mix Mode
  70. RDPAGE2        equ        $C01C        ;Read Page 2 setting
  71. RDHIRES        equ        $C01D        ;Read HiRes setting
  72. TXTCLR        equ        $C050        ;Clear Text Mode
  73. TXTSET        equ        $C051        ;Set Text Mode
  74. MIXCLR        equ        $C052        ;Clear Mixed Mode
  75. MIXSET        equ        $C053        ;Set Mixed Mode
  76. TXTPAGE1    equ        $C054        ;Set Text Page 1
  77. TXTPAGE2    equ        $C055        ;Set Text page 2
  78. LORES        equ        $C056        ;Set LoRes Graphics
  79. HIRES        equ        $C057        ;Set HiRes Graphics
  80. CLRAN3        equ        $C05E        ;Clear annunciator 3
  81. SETAN3        equ        $C05F        ;Set annunciator 3
  82.  
  83. ESC            equ        $9B            ;High bit set ASCII ESC Key
  84.  
  85. Blk_sig1    equ        $01
  86. Blk_sig2    equ        $03
  87. Blk_sig3    equ        $05
  88. SPort_sig    equ        $07
  89. SPort_ID    equ        $FB
  90.  
  91. Ext_SPort    equ        %10000000    ;Bit 7
  92. SCSI        equ        %00000010    ;Bit 2
  93.  
  94. No_Err        equ        $00
  95. IO_Err        equ        $27
  96. No_dev        equ        $28
  97.  
  98. ;*******************************************************
  99.  
  100.             EXPORT    P8_Scanner
  101. P8_Scanner    PROC
  102.                                 ;
  103.                                 ; Main Code Segment.
  104.                                 ;
  105.  
  106.             jsr        find_card
  107.             jsr        find_scanr
  108.             jsr        htone_filter
  109.             jsr        def_window
  110.             jsr        start_scan
  111.             jsr        get_data
  112.             jsr        display
  113.             bcc        P8_Scanner
  114.             rts
  115.  
  116. ;*******************************************************
  117. ;
  118. ;    CODE SAMPLE #1
  119. ;
  120. ;    This first code segment walks the slots starting at
  121. ;    slot 7, looking first for a card of any kind.  Once
  122. ;    found, we check the ID bytes for a Smartport card.
  123. ;    Once found we check the ID Type byte to see if it is
  124. ;    a SCSI Card.  If it passes all these tests, we then
  125. ;    issue a Device $00 Status $00 call to further ensure
  126. ;    that this is the Apple High-Speed SCSI Card.
  127. ;
  128. ;*******************************************************
  129.  
  130. find_card
  131.                                 ;
  132.                                 ; Save the current Zero
  133.                                 ; Page values before
  134.                                 ; using them.
  135.                                 ;
  136.             lda        <My_ZPage
  137.             pha
  138.             lda        <My_ZPage+1
  139.             pha
  140.                                 ;
  141.                                 ; Start at Slot 7.
  142.                                 ;
  143.             lda        #slot_7
  144.             sta        <My_ZPage+1    ;Zero Page
  145.             sta        slot+1        ;For Safe keeping
  146.             stz        <My_ZPage
  147.             stz        slot
  148.                                 ;
  149.                                 ; Is it a Smartport Card?
  150.                                 ;
  151. @chk_smart    ldy        #Blk_sig1
  152.             lda        (My_ZPage),y;Block_device Signature Byte
  153.             cmp        #$20        ;#1 = $20
  154.             bne        @next_slot
  155.  
  156.             ldy        #Blk_sig2
  157.             lda        (My_ZPage),y;Block_device Signature Byte
  158.             bne        @next_slot    ;#2 = $00
  159.  
  160.             ldy        #Blk_sig3
  161.             lda        (My_ZPage),y;Block_device Signature Byte
  162.             cmp        #$03        ;#3 = $03
  163.             bne        @next_slot
  164.  
  165.             ldy        #SPort_sig
  166.             lda        (My_ZPage),y;SmartPort Signature Byte
  167.             bne        @next_slot    ;#1 = $00
  168.                                 ;
  169.                                 ; We have a Smartport
  170.                                 ; Device.  Is it SCSI with
  171.                                 ; Extended SmartPort?
  172.                                 ;
  173.             ldy        #SPort_ID
  174.             lda        (My_ZPage),y
  175.             and        #Ext_SPort+\
  176.                     SCSI
  177.             cmp        #Ext_SPort+\
  178.                     SCSI
  179.             bne        @next_slot
  180.                                 ;
  181.                                 ; Is it an Apple High-
  182.                                 ; Speed SCSI Card?
  183.                                 ;
  184.             jsr        is_it_appl
  185.             bcc        @exit
  186.                                 ;
  187.                                 ; Check the Next Slot.
  188.                                 ;
  189. @next_slot    lda        <My_ZPage+1
  190.             dec        a
  191.             sta        <My_ZPage+1
  192.             sta        slot+1
  193.             cmp        #slot_1
  194.             bge        @chk_smart
  195.             lda        #No_dev        ;No Device Error
  196.                                 ;
  197.                                 ; Clean Exit
  198.                                 ;
  199. @exit        tax
  200.             pla
  201.             sta        <My_ZPage+1
  202.             pla
  203.             sta        <My_ZPage
  204.             txa
  205.  
  206.             cmp        #$01        ;Set Carry if Non-Zero
  207.             rts
  208.                                 ;
  209.                                 ; This routine determines
  210.                                 ; if the card is the new
  211.                                 ; High-Speed SCSI Card.
  212.                                 ;
  213. is_it_appl    ldy        #$ff
  214.             lda        (My_ZPage),y
  215.             clc
  216.             adc        #$03        ;Set Smartport Entry Address
  217.             sta        card_ntry
  218.  
  219.             lda        <My_ZPage+1
  220.             sta        card_ntry+1
  221.  
  222.             jsr        call_card
  223.             dc.b    $00            ;Status Call Command Number
  224.             dc.w    stat_list1
  225.                                 ;
  226.                                 ; Check the Results
  227.                                 ;
  228.             lda        stat_data+2    ;Low Byte of Vendor ID
  229.             cmp        #$01        ;Must be $01
  230.             bne        @non_apple
  231.  
  232.             lda        stat_data+3    ;High Byte of Vendor ID
  233.             bne        @non_apple    ;Must be $00
  234.  
  235.             lda        stat_data+4    ;Low Byte of Version
  236.             bne        @non_apple    ;Should be Null
  237.  
  238.             lda        stat_data+5    ;High Byte of Version
  239.             bne        @non_apple    ;Should be Null
  240.  
  241.             clc                    ;Acc. 0 by previous LDA
  242.             bra        @done
  243.  
  244. @non_apple    lda        #No_dev        ;Device not found.
  245.             sec
  246.                                 ;
  247.                                 ; Restore ZPage
  248.                                 ;
  249. @done        pha
  250.             php
  251.             lda        slot
  252.             sta        <My_ZPage
  253.             lda        slot+1
  254.             sta        <My_ZPage+1
  255.             plp
  256.             pla
  257.             rts
  258.  
  259. slot        dc.w    $0000
  260.  
  261. ;*******************************************************
  262.  
  263. call_card    jmp        (card_ntry)
  264.  
  265. card_ntry    dc.w    $0000
  266.  
  267. ;*******************************************************
  268.  
  269. stat_list1    dc.b    $03            ;PCount = 3
  270.             dc.b    $00            ;Device = Card
  271.             dc.w    stat_data    ;Data returned here
  272.             dc.b    $00            ;Get Host Status Call
  273.  
  274. ;*******************************************************
  275.  
  276. stat_data    dcb.b    64,0        ;Our Buffer.
  277.  
  278. ;*******************************************************
  279. ;
  280. ;    CODE SAMPLE #2
  281. ;
  282. ;    This code segment walks the unit numbers from the
  283. ;    SCSI Card starting at unit 2 and going to unit 0 to
  284. ;    get the actual unit number count.  Once this is
  285. ;    done, we start at unit 1 and walk forward until we
  286. ;    find the scanner.
  287. ;
  288. ;*******************************************************
  289.  
  290. find_scanr
  291.                                 ;
  292.                                 ; First we issue a
  293.                                 ; Status call to device
  294.                                 ; number 2.  This will
  295.                                 ; force the card to
  296.                                 ; build its tables if it
  297.                                 ; has not yet done so.
  298.                                 ;
  299.             lda        #$02
  300.             sta        dev_num2
  301.             stz        stat_code2
  302.  
  303.             jsr        call_card
  304.             dc.b    $00
  305.             dc.w    stat_list2
  306.             bcs        @error
  307.                                 ;
  308.                                 ; Now call Unit 0 to
  309.                                 ; find out the total
  310.                                 ; device count.
  311.                                 ;
  312.             stz        dev_num2
  313.             jsr        call_card
  314.             dc.b    $00            ;Status Call Command Number
  315.             dc.w    stat_list2
  316.             bcs        @error
  317.  
  318.             lda        stat_data2    ;Get the Total Device
  319.             sta        dev_count    ;Count
  320.  
  321.             lda        #$03        ;Set up for DIB Status
  322.             sta        stat_code2    ;Calls
  323.  
  324. @loop        lda        dev_num2    ;First time we increment
  325.             cmp        dev_count    ;a zero giving a device
  326.             bge        @error        ;number of 1.
  327.  
  328.             inc        dev_num2
  329.             jsr        call_card
  330.             dc.b    $00            ;Status Call Command Number
  331.             dc.w    stat_list2
  332.             bcs        @error
  333.  
  334.             lda        d_type
  335.             cmp        #$08        ;Is it Type = Scanner?
  336.             bne        @loop        ;No.
  337.  
  338.             lda        d_stype
  339.             cmp        #$A0        ;Subtype = $A0?
  340.             bne        @loop        ;No
  341.                                 ;
  342.                                 ; Scan string is a Pascal
  343.                                 ; String.  A length byte
  344.                                 ; followed by ASCII.  We
  345.                                 ; want to make sure they
  346.                                 ; are both the same length
  347.                                 ; as well as the same text.
  348.                                 ;
  349.             ldx        id_str_len
  350. @str_loop    lda        id_str_len,x
  351.             cmp        scan_str,x
  352.             bne        @loop
  353.             dex
  354.             bne        @str_loop
  355.  
  356.             lda        dev_num2    ;We have our Scanner
  357.             sta        scan_dnum
  358.             lda        #No_Err
  359.             clc
  360.             rts
  361.  
  362. @error        lda        #No_dev        ;Device not found.
  363.             sec
  364.             rts
  365.  
  366. ;*******************************************************
  367.  
  368. scan_str    dc.b    'APPLE   SCANNER '    ;4 Spaces between
  369.                                         ;1 Sace after
  370. dev_count    dc.b    $00
  371.  
  372. ;*******************************************************
  373.  
  374. scan_dnum    dc.b    $00            ;Scanner Device Number
  375.  
  376. ;*******************************************************
  377.  
  378. stat_list2    dc.b    $03            ;PCount = 3
  379. dev_num2    dc.b    $00            ;Device number
  380.             dc.w    stat_data2    ;Data returned here
  381. stat_code2    dc.b    $00            ;Status Code
  382.  
  383. ;*******************************************************
  384.  
  385. stat_data2                        ;Our Buffer. Used over.
  386. d_stat        dc.b    $00            ;Device Status Byte
  387. blk_low        dc.b    $00            ;Block Count (Low)
  388. blk_mid        dc.b    $00            ;Block Count (Mid)
  389. blk_hi        dc.b    $00            ;Block Count (High)
  390. id_str_len    dc.b    $00            ;ID String Length
  391. id_str        dcb.b    16,$00        ;ID STring (16 Bytes)
  392. d_type        dc.b    $00            ;Device Type
  393. d_stype        dc.b    $00            ;Device Subtype
  394. d_version    dc.w    $00            ;Version Word
  395.  
  396. ;*******************************************************
  397. ;
  398. ;    CODE SAMPLE #3
  399. ;
  400. ;    This code segment issues an Apple Scanner SEND
  401. ;    Command by using the Apple SCSI Card Generic SCSI
  402. ;    call ($2B).  By so doing we can send our halftone
  403. ;    filter to the Scanner.
  404. ;
  405. ;*******************************************************
  406.  
  407. htone_filter
  408.                                 ;
  409.                                 ; Issue the Call
  410.                                 ;
  411.             lda        scan_dnum
  412.             sta        dev_num3
  413.  
  414.             jsr        call_card
  415.             dc.b    $04            ;Control Call Command Number
  416.             dc.w    cmd_list3
  417.             rts
  418.  
  419. ;*******************************************************
  420.  
  421. cmd_list3    dc.b    $03            ;PCount = 3
  422. dev_num3    dc.b    $04            ;Device number
  423.             dc.w    filter_data    ;Pointer to data
  424.             dc.b    $2B            ;Control Code
  425.  
  426. ;*******************************************************
  427.  
  428. filter_data                        ;Our Data
  429.             dc.w    24            ;Total Length of Parms
  430.             dc.l    send_fltr    ;CDB Pointer (Long)
  431.             dc.l    DCData3        ;DCMove Ptr (Long)
  432.             dc.l    $00000000    ;Rqst Sense Ptr (Long)
  433.             dc.b    $00            ;Reserved
  434.             dc.b    $00            ;SCSI Status
  435.             dc.b    $00            ;Command Count
  436.             dc.l    $00000011    ;Trans Count (Long)
  437.             dc.b    $00            ;DMA Mode
  438.             dc.l    $00000000    ;Reserved (Long)
  439.  
  440. ;*******************************************************
  441.  
  442. send_fltr    dc.b    $2A            ;Scanner SEND Command
  443.             dc.b    $00            ;Reserved
  444.             dc.b    $02            ;Transfer Type
  445.             dc.b    $00            ;Reserved
  446.             dc.b    $00            ;Reserved
  447.             dc.b    $02            ;Transfer ID Byte
  448.             dc.b    $00            ;Reserved
  449.             dc.b    $00            ;Transfer Length (High)
  450.             dc.b    $11            ;Transfer Length (Low)
  451.             dc.b    $00            ;Reserved
  452.  
  453. ;*******************************************************
  454.  
  455. DCData3        dc.l    send_data    ;Scanner SEND Data Ptr
  456.             dc.l    $00000011    ;Transfer Count
  457.             dc.l    $00000000    ;Offset
  458.             dc.l    $00000000    ;Reserved
  459.  
  460.             dc.l    $00000000    ;DCStop
  461.             dc.l    $00000000    ;Reserved
  462.             dc.l    $00000000    ;Reserved
  463.             dc.l    $00000000    ;Reserved
  464.  
  465. ;*******************************************************
  466.  
  467. send_data    dc.b    $44            ;4 X 4 Matrix Size
  468.             dc.b    $08            ;Pel 0
  469.             dc.b    $88            ;Pel 1
  470.             dc.b    $28            ;Pel 2
  471.             dc.b    $A8            ;Pel 3
  472.             dc.b    $C8            ;Pel 4
  473.             dc.b    $48            ;Pel 5
  474.             dc.b    $E8            ;Pel 6
  475.             dc.b    $68            ;Pel 7
  476.             dc.b    $38            ;Pel 8
  477.             dc.b    $B8            ;Pel 9
  478.             dc.b    $18            ;Pel 10
  479.             dc.b    $98            ;Pel 11
  480.             dc.b    $F8            ;Pel 12
  481.             dc.b    $78            ;Pel 13
  482.             dc.b    $D8            ;Pel 14
  483.             dc.b    $58            ;Pel 15
  484.  
  485. ;*******************************************************
  486. ;
  487. ;    CODE SAMPLE #4
  488. ;
  489. ;    This code segment issues an Apple Scanner Define
  490. ;    Window Parameters Command by using the Apple SCSI
  491. ;    Card Generic SCSI call ($2B).  This command defines
  492. ;    the area of the scanner glass we want to scan
  493. ;
  494. ;*******************************************************
  495.  
  496. def_window
  497.                                 ;
  498.                                 ; Issue the Call
  499.                                 ;
  500.             lda        scan_dnum
  501.             sta        dev_num4
  502.  
  503.             jsr        call_card
  504.             dc.b    $04            ;Control Call Command Number
  505.             dc.w    cmd_list4
  506.             rts
  507.  
  508. ;*******************************************************
  509.  
  510. cmd_list4    dc.b    $03            ;PCount = 3
  511. dev_num4    dc.b    $00            ;Device number
  512.             dc.w    def_wndo    ;Pointer to data
  513.             dc.b    $2B            ;Control Code
  514.  
  515. ;*******************************************************
  516.  
  517. def_wndo                        ;Our Data
  518.             dc.w    24            ;Total Length of Parms
  519.             dc.l    def_wnd_cmd    ;CDB Pointer (Long)
  520.             dc.l    DCData4        ;DCMove Ptr (Long)
  521.             dc.l    $00000000    ;Rqst Sense Ptr (Long)
  522.             dc.b    $00            ;Reserved
  523.             dc.b    $00            ;SCSI Status
  524.             dc.b    $00            ;Command Count
  525.             dc.l    8+40        ;Trans Count (Long)
  526.             dc.b    $00            ;DMA Mode
  527.             dc.l    $00000000    ;Reserved (Long)
  528.  
  529. ;*******************************************************
  530.  
  531. def_wnd_cmd    dc.b    $24            ;Scanner Define Window
  532.                                 ;Parameters Command
  533.             dc.b    $00            ;Reserved
  534.             dc.b    $00            ;Reserved
  535.             dc.b    $00            ;Reserved
  536.             dc.b    $00            ;Reserved
  537.             dc.b    $00            ;Reserved
  538.             dc.b    $00            ;Transfer Length (High)
  539.             dc.b    $00            ;Transfer Length (Mid)
  540.             dc.b    8+40        ;Transfer Length (Low)
  541.             dc.b    $80            ;Apple Bit
  542.  
  543. ;*******************************************************
  544.  
  545. DCData4        dc.l    wndo_data    ;Scanner Window Data Ptr
  546.             dc.l    8+40        ;Transfer Count
  547.             dc.l    $00000000    ;Offset
  548.             dc.l    $00000000    ;Reserved
  549.  
  550.             dc.l    $00000000    ;DCStop
  551.             dc.l    $00000000    ;Reserved
  552.             dc.l    $00000000    ;Reserved
  553.             dc.l    $00000000    ;Reserved
  554.  
  555. ;*******************************************************
  556. ;    NOTE:  Remember that all values that are longer than
  557. ;    1 byte are in reversed order from natice 65xxx code.
  558. ;*******************************************************
  559.  
  560. wndo_data    dcb.b    6,$00        ;Reserved
  561.             dc.b    $00            ;Transfer Length (High)
  562.             dc.b    40            ;Transfer Length (Low)
  563.  
  564.             dc.b    $01            ;Window Identifier
  565.             dc.b    $00            ;Reserved
  566.  
  567.             dc.b    $00            ;X Resolution (High)
  568.             dc.b    75            ;X Resolution (Low)
  569.  
  570.             dc.b    $00            ;Y Resolution (High)
  571.             dc.b    75            ;Y Resolution (Low)
  572.                                 ;
  573.                                 ; We will use the corner as
  574.                                 ; Our Upper Left Possition.
  575.                                 ; This is at coordinate 0,0
  576.                                 ;
  577.             dc.b    $00            ;Upper Left X (High)
  578.             dc.b    $00            ;Upper Left X (Mid High)
  579.             dc.b    $00            ;Upper Left X (Mid Low)
  580.             dc.b    $00            ;Upper Left X (Low)
  581.  
  582.             dc.b    $00            ;Upper Left Y (High)
  583.             dc.b    $00            ;Upper Left Y (Mid High)
  584.             dc.b    $00            ;Upper Left Y (Mid Low)
  585.             dc.b    $00            ;Upper Left Y (Low)
  586.                                 ;
  587.                                 ; Width is defined as the number
  588.                                 ; of 1/1200-inch increments on
  589.                                 ; the horizontal axis; must be on
  590.                                 ; a byte boundry for both the
  591.                                 ; start and end points.  We will
  592.                                 ; set for 4 Inches and drop the
  593.                                 ; extra.
  594.                                 ; 
  595.             dc.b    $00            ;Width (High)
  596.             dc.b    $00            ;Width (Mid High)
  597.             dc.b    4*1200/256    ;Width (Mid Low)
  598.             dc.b    4*1200        ;Width (Low)
  599.                                 ;
  600.                                 ; Length is defined as the number
  601.                                 ; of 1/1200-inch increments on the
  602.                                 ; vertical axis.  We want ≈ 2 1/2
  603.                                 ; inches or 3072 increments
  604.                                 ; 
  605.             dc.b    $00            ;Length (High)
  606.             dc.b    $00            ;Length (Mid High)
  607.             dc.b    3072/256    ;Length (Mid Low)
  608.             dc.b    3072        ;Length (Low)
  609.  
  610.             dc.b    $80            ;Median Brightness
  611.             dc.b    $80            ;Median Threshold
  612.             dc.b    $80            ;Median Contrast
  613.  
  614.             dc.b    $01            ;Image Composition (Halftone)
  615.             dc.b    $01            ;Bits per Pixel
  616.  
  617.             dc.b    $00            ;Halftone Mask Always $00 (High)
  618.             dc.b    $02            ;Downloaded Mask Pattern (Low)
  619.  
  620.             dc.b    $03            ;Padding Type
  621.             dcb.b    2,$00        ;Reserved
  622.             dc.b    $00            ;Compression Type (None)
  623.             dcb.b    7,$00        ;Scanner Ref. is wrong.  Says 5.
  624.  
  625. ;*******************************************************
  626. ;
  627. ;    CODE SAMPLE #5
  628. ;
  629. ;    This code segment issues an Apple Scanner SCAN
  630. ;    Command by using the Apple SCSI Card Generic SCSI
  631. ;    call ($2B).  This starts the actual scanning.
  632. ;
  633. ;*******************************************************
  634.  
  635. start_scan
  636.                                 ;
  637.                                 ; Issue the Call
  638.                                 ;
  639.             lda        scan_dnum
  640.             sta        dev_num5
  641.  
  642.             jsr        call_card
  643.             dc.b    $04            ;Control Call Command Number
  644.             dc.w    cmd_list5
  645.             rts
  646.  
  647. ;*******************************************************
  648.  
  649. cmd_list5    dc.b    $03            ;PCount = 3
  650. dev_num5    dc.b    $00            ;Device number
  651.             dc.w    scan_cmd    ;Pointer to data
  652.             dc.b    $2B            ;Control Code
  653.  
  654. ;*******************************************************
  655.  
  656. scan_cmd                        ;Our Data
  657.             dc.w    24            ;Total Length of Parms
  658.             dc.l    do_scan        ;CDB Pointer (Long)
  659.             dc.l    DCData5        ;DCMove Ptr (Long)
  660.             dc.l    $00000000    ;Rqst Sense Ptr (Long)
  661.             dc.b    $00            ;Reserved
  662.             dc.b    $00            ;SCSI Status
  663.             dc.b    $00            ;Command Count
  664.             dc.l    $00000001    ;Trans Count (Long)
  665.             dc.b    $00            ;DMA Mode
  666.             dc.l    $00000000    ;Reserved (Long)
  667.  
  668. ;*******************************************************
  669.  
  670. do_scan        dc.b    $1B            ;SCAN
  671.                                 ;Parameters Command
  672.             dcb.b    3,$00        ;Reserved
  673.             dc.b    1            ;Transfer Length (Low)
  674.             dc.b    $00            ;Wait and Home Bits = 0
  675.  
  676. ;*******************************************************
  677.  
  678. DCData5        dc.l    window_ID    ;Scanner Window Data Ptr
  679.             dc.l    1            ;Transfer Count
  680.             dc.l    $00000000    ;Offset
  681.             dc.l    $00000000    ;Reserved
  682.  
  683.             dc.l    $00000000    ;DCStop
  684.             dc.l    $00000000    ;Reserved
  685.             dc.l    $00000000    ;Reserved
  686.             dc.l    $00000000    ;Reserved
  687.  
  688. ;*******************************************************
  689.  
  690. window_ID    dc.b    $01            ;Window Identifier
  691.  
  692. ;*******************************************************
  693. ;
  694. ;    CODE SAMPLE #6
  695. ;
  696. ;    This code segment issues a series of calls to the
  697. ;    Apple Scanner by using the Apple SCSI Card Generic
  698. ;    SCSI call ($2B).  We first issue a GET DATA STATUS
  699. ;    to see if there is enough data.  Then we read in a
  700. ;    single Scan Line with a READ Call.  The data is then
  701. ;    converted and placed in a video buffer.
  702. ;
  703. ;*******************************************************
  704.  
  705. get_data
  706.             stz        scan_line    ;Init the scanline to 0
  707.                                 ;
  708.                                 ; Issue the Call
  709.                                 ;
  710. @get_data2    lda        scan_dnum
  711.             sta        dev_num6
  712.             sta        dev_num65
  713.  
  714.             jsr        call_card
  715.             dc.b    $04            ;Control Call Command Number
  716.             dc.w    cmd_list6
  717.             bcs        @out
  718.                                 ;
  719.                                 ; Is there enough Data?
  720.                                 ; Enough data = 1 scan
  721.                                 ; line of 4 inches at 75
  722.                                 ; DPI or 300 pixels.  At
  723.                                 ; 8 pixels per byte, the
  724.                                 ; data will be padded to
  725.                                 ; 38 bytes.
  726.                                 ;
  727.             lda        scan_data
  728.             bne        @have_line
  729.             lda        scan_data+1
  730.             bne        @have_line
  731.             lda        scan_data+2
  732.             cmp        #38            ;Decimal 38
  733.             blt        get_data
  734.                                 ;
  735.                                 ; We have the data.  Read
  736.                                 ; it.
  737.                                 ;
  738. @have_line    jsr        call_card
  739.             dc.b    $04            ;Control Call Command Number
  740.             dc.w    cmd_list65
  741.             bcs        @out
  742.                                 ;
  743.                                 ; Now we need to invert
  744.                                 ; the data.
  745.                                 ;
  746.             lda        #40            ;40 bytes/line
  747.             sta        byte_count
  748.             stz        byte_index
  749. @loop_1        lda        #$07
  750.             sta        seven        ;Pixels/byte
  751. @loop_2        ldx        #38-2
  752.             asl        raw_image+37;Shift bits out the top to
  753. @loop_3        rol        raw_image,x    ;the next byte 1 at a time
  754.             dex
  755.             bpl        @loop_3
  756.             ldx        byte_index    ;Shift the last bit in to
  757.             ror        screen,x    ;this byte.  This reverses the
  758.             dec        seven        ;bit ordering. Also taking 8
  759.             bne        @loop_2        ;bits per byte down to 7
  760.             lsr        screen,x
  761.             inc        byte_index
  762.             dec        byte_count
  763.             bne        @loop_1
  764.                                 ;
  765.                                 ; Move data to Scan Line
  766.                                 ;
  767.             ldx        scan_line
  768.             jsr        on_screen
  769.             inc        scan_line
  770.             bra        @get_data2
  771.  
  772. @out        lda        #$00
  773.             clc
  774.             rts
  775.  
  776. ;*******************************************************
  777.  
  778. scan_line    dc.b    $00            ;Scan Line Index
  779. byte_count    dc.b    $00            ;Number of bytes left
  780. byte_index    dc.b    $00            ;Current Byte in use
  781. seven        dc.b    $00            ;Count off 7 pixels
  782. screen        dcb.b    40,0        ;Place to do the screen
  783.  
  784. ;*******************************************************
  785.  
  786. cmd_list6    dc.b    $03            ;PCount = 3
  787. dev_num6    dc.b    $00            ;Device number
  788.             dc.w    gd_status    ;Pointer to data
  789.             dc.b    $2B            ;Control Code
  790.  
  791. cmd_list65    dc.b    $03            ;PCount = 3
  792. dev_num65    dc.b    $00            ;Device number
  793.             dc.w    read        ;Pointer to data
  794.             dc.b    $2B            ;Control Code
  795.  
  796. ;*******************************************************
  797.  
  798. gd_status                        ;Our Data
  799.             dc.w    24            ;Total Length of Parms
  800.             dc.l    get_stat    ;CDB Pointer (Long)
  801.             dc.l    DCData6        ;DCMove Ptr (Long)
  802.             dc.l    $00000000    ;Rqst Sense Ptr (Long)
  803.             dc.b    $00            ;Reserved
  804.             dc.b    $00            ;SCSI Status
  805.             dc.b    $00            ;Command Count
  806.             dc.l    $0000000C    ;Trans Count (Long)
  807.             dc.b    $00            ;DMA Mode
  808.             dc.l    $00000000    ;Reserved (Long)
  809.  
  810. read                            ;Our Data
  811.             dc.w    24            ;Total Length of Parms
  812.             dc.l    get_data2    ;CDB Pointer (Long)
  813.             dc.l    DCData65    ;DCMove Ptr (Long)
  814.             dc.l    $00000000    ;Rqst Sense Ptr (Long)
  815.             dc.b    $00            ;Reserved
  816.             dc.b    $00            ;SCSI Status
  817.             dc.b    $00            ;Command Count
  818.             dc.l    $00000026    ;Trans Count (Long)
  819.             dc.b    $00            ;DMA Mode
  820.             dc.l    $00000000    ;Reserved (Long)
  821.  
  822. ;*******************************************************
  823.  
  824. get_stat    dc.b    $34            ;GET DATA STATUS
  825.                                 ;Parameters Command
  826.             dcb.b    7,$00        ;Reserved
  827.             dc.b    12            ;Transfer Length (Low)
  828.             dc.b    $00            ;Wait and Home Bits = 0
  829.  
  830. get_data2    dc.b    $28            ;READ
  831.                                 ;Parameters Command
  832.             dcb.b    4,$00        ;Reserved
  833.             dc.b    $01            ;Window ID
  834.             dc.b    $00            ;Transfer Length (High)
  835.             dc.b    $00            ;Transfer Length (Mid)
  836.             dc.b    $26            ;Transfer Length (Low)
  837.             dc.b    $00            ;Wait and Home Bits = 0
  838.  
  839. ;*******************************************************
  840.  
  841. DCData6        dc.l    data_cnt    ;Data Pointer
  842.             dc.l    12            ;Transfer Count
  843.             dc.l    $00000000    ;Offset
  844.             dc.l    $00000000    ;Reserved
  845.  
  846.             dc.l    $00000000    ;DCStop
  847.             dc.l    $00000000    ;Reserved
  848.             dc.l    $00000000    ;Reserved
  849.             dc.l    $00000000    ;Reserved
  850.  
  851. DCData65    dc.l    raw_image    ;Data Pointer
  852.             dc.l    38            ;Transfer Count
  853.             dc.l    $00000000    ;Offset
  854.             dc.l    $00000000    ;Reserved
  855.  
  856.             dc.l    $00000000    ;DCStop
  857.             dc.l    $00000000    ;Reserved
  858.             dc.l    $00000000    ;Reserved
  859.             dc.l    $00000000    ;Reserved
  860.  
  861. ;*******************************************************
  862.  
  863. data_cnt                        ;Data Space
  864.             dcb.b    2,$00        ;Reserved
  865.             dc.b    $00            ;Data Length
  866.             dc.b    $00            ;Block
  867.             dc.b    $00            ;Window Identifier
  868.             dcb.b    4,$00        ;Reserved
  869. scan_data    dc.b    $00            ;Scan Data (High)
  870.             dc.b    $00            ;Scan Data (Mid)
  871.             dc.b    $00            ;Scan Data (Low)
  872.  
  873. raw_image    dcb.b    38,$00        ;Scanned Data Image
  874.  
  875. ;*******************************************************
  876.  
  877. on_screen    lda        scan_tbl_lo,x
  878.             sta        <$42
  879.             lda        scan_tbl_hi,x
  880.             sta        <$43
  881.             ldx        #40-1
  882.             ldy        #40-1
  883. @loop        lda        screen,x
  884.             eor        #$7f
  885.             sta        ($42),y
  886.             dex
  887.             dey
  888.             bpl        @loop
  889.             
  890.             clc
  891.             rts
  892.  
  893. scan_tbl_lo    dcb.b    8,$00        ;Lines 0-7
  894.             dcb.b    8,$80        ;Lines 8-15
  895.             dcb.b    8,$00        ;Lines 16-23
  896.             dcb.b    8,$80        ;Lines 24-31
  897.             dcb.b    8,$00        ;Lines 32-39
  898.             dcb.b    8,$80        ;Lines 40-47
  899.             dcb.b    8,$00        ;Lines 48-55
  900.             dcb.b    8,$80        ;Lines 56-63
  901.  
  902.             dcb.b    8,$28        ;Lines 64-71
  903.             dcb.b    8,$a8        ;Lines 72-79
  904.             dcb.b    8,$28        ;Lines 80-87
  905.             dcb.b    8,$a8        ;Lines 88-95
  906.             dcb.b    8,$28        ;Lines 96-103
  907.             dcb.b    8,$a8        ;Lines 104-111
  908.             dcb.b    8,$28        ;Lines 112-119
  909.             dcb.b    8,$a8        ;Lines 120-127
  910.  
  911.             dcb.b    8,$50        ;Lines 128-135
  912.             dcb.b    8,$d0        ;Lines 136-143
  913.             dcb.b    8,$50        ;Lines 144-151
  914.             dcb.b    8,$d0        ;Lines 152-159
  915.             dcb.b    8,$50        ;Lines 160-167
  916.             dcb.b    8,$d0        ;Lines 168-175
  917.             dcb.b    8,$50        ;Lines 176-183
  918.             dcb.b    8,$d0        ;Lines 184-191
  919.  
  920. scan_tbl_hi    dc.b    $20,$24,$28,$2c,$30,$34,$38,$3c
  921.             dc.b    $20,$24,$28,$2c,$30,$34,$38,$3c
  922.             dc.b    $21,$25,$29,$2d,$31,$35,$39,$3d
  923.             dc.b    $21,$25,$29,$2d,$31,$35,$39,$3d
  924.             dc.b    $22,$26,$2a,$2e,$32,$36,$3a,$3e
  925.             dc.b    $22,$26,$2a,$2e,$32,$36,$3a,$3e
  926.             dc.b    $23,$27,$2b,$2f,$33,$37,$3b,$3f
  927.             dc.b    $23,$27,$2b,$2f,$33,$37,$3b,$3f
  928.  
  929.             dc.b    $20,$24,$28,$2c,$30,$34,$38,$3c
  930.             dc.b    $20,$24,$28,$2c,$30,$34,$38,$3c
  931.             dc.b    $21,$25,$29,$2d,$31,$35,$39,$3d
  932.             dc.b    $21,$25,$29,$2d,$31,$35,$39,$3d
  933.             dc.b    $22,$26,$2a,$2e,$32,$36,$3a,$3e
  934.             dc.b    $22,$26,$2a,$2e,$32,$36,$3a,$3e
  935.             dc.b    $23,$27,$2b,$2f,$33,$37,$3b,$3f
  936.             dc.b    $23,$27,$2b,$2f,$33,$37,$3b,$3f
  937.  
  938.             dc.b    $20,$24,$28,$2c,$30,$34,$38,$3c
  939.             dc.b    $20,$24,$28,$2c,$30,$34,$38,$3c
  940.             dc.b    $21,$25,$29,$2d,$31,$35,$39,$3d
  941.             dc.b    $21,$25,$29,$2d,$31,$35,$39,$3d
  942.             dc.b    $22,$26,$2a,$2e,$32,$36,$3a,$3e
  943.             dc.b    $22,$26,$2a,$2e,$32,$36,$3a,$3e
  944.             dc.b    $23,$27,$2b,$2f,$33,$37,$3b,$3f
  945.             dc.b    $23,$27,$2b,$2f,$33,$37,$3b,$3f
  946.  
  947. ;*******************************************************
  948. ;
  949. ;    CODE SAMPLE #7
  950. ;
  951. ;    This code segment toggles the HiRes Soft switches so
  952. ;    that we can see what was just scanned.
  953. ;
  954. ;*******************************************************
  955.  
  956. display
  957.                                 ;
  958.                                 ; Save the Current State
  959.                                 ;
  960.             lda        RDTEXT
  961.             sta        @text        ;Text/Graphics
  962.  
  963.             lda        RDMIX
  964.             sta        @mixed        ;Mixed?
  965.  
  966.             lda        RDPAGE2
  967.             sta        @page        ;Page 1 or 2
  968.  
  969.             lda        RDHIRES
  970.             sta        @hires        ;HiRes Mode?
  971.  
  972.             lda        RD80COL
  973.             sta        @80col        ;80-Column Mode?
  974.  
  975.             lda        CLR80VID    ;40-Column Mode.
  976.             lda        TXTCLR        ;Standard Apple II Graphics
  977.             lda        MIXCLR        ;Clear Mixed Mode
  978.             lda        TXTPAGE1    ;Page 1
  979.             lda        HIRES        ;HiRes Mode
  980.             lda        CLRAN3        ;Clear annunciator 3
  981.  
  982.  
  983.             sta        KBD_STRB    ;Clear Key Strobe
  984. @key_loop    lda        KBD            ;Get key
  985.             bpl        @key_loop    ;Wait for Key Press
  986.             sta        KBD_STRB    ;Clear Key Strobe
  987.             cmp        #ESC        ;ESC Key
  988.             clc
  989.             bne        @chk_txt
  990.             sec                    ;Exit on ESC
  991.  
  992.             lda        SETAN3        ;Set annunciator 3
  993.  
  994. @chk_txt    lda        @text
  995.             bpl        @chk_mix
  996.             sta        TXTSET        ;Text on
  997.  
  998. @chk_mix    lda        @mixed
  999.             bpl        @chk_page
  1000.             sta        MIXSET        ;Mixed on
  1001.  
  1002. @chk_page    lda        @page
  1003.             bpl        @chk_hires
  1004.             sta        TXTPAGE2    ;Page 2
  1005.  
  1006. @chk_hires    lda        @hires
  1007.             bpl        @chk_40col
  1008.             sta        LORES        ;HiRes Off
  1009.  
  1010. @chk_40col    lda        @80col
  1011.             bpl        @rts
  1012.             sta        SET80VID    ;80-Column on.
  1013.  
  1014. @rts        rts
  1015.  
  1016. @text        dc.b    $00
  1017. @mixed        dc.b    $00
  1018. @page        dc.b    $00
  1019. @hires        dc.b    $00
  1020. @80col        dc.b    $00
  1021.  
  1022. ;*******************************************************
  1023.  
  1024.             ENDP
  1025.             
  1026.             END
  1027.  
  1028.